﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Windows;
using System.IO;
using System.Collections.ObjectModel;

namespace FileSystem
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            ReSetSkin();
        }
        /// <summary>
        /// 重置皮肤
        /// </summary>
        public void ReSetSkin()
        {
            var resourcePath = SkinPath();
            if (string.IsNullOrEmpty(resourcePath))
            {
                return;
            }
            Uri uri=new Uri(resourcePath,UriKind.Relative);
            ResourceDictionary rd = Application.LoadComponent(uri) as ResourceDictionary;
            Collection<ResourceDictionary> rds = this.Resources.MergedDictionaries;
            if (rds.Count>0)
            {
                rds.Clear();
            }
            rds.Add(rd);
        }

        /// <summary>
        /// 获取可用皮肤路径
        /// </summary>
        /// <returns></returns>
        private string SkinPath()
        {
            var path = StaticValue.AppPath + "/Resource/Data/SkinOption.xml";
            var query = from q in XDocument.Load(path).Elements("Options").Elements("Option")
                        where q.Element("App").Value=="True"
                        select q.Element("SkinUri").Value;
            return query.FirstOrDefault();
        }
    }
}
